var gulp = require('gulp');
var less = require('gulp-less');
var autoprefixer = require('gulp-autoprefixer'); // 兼容代码自动补全
var cleanCss = require('gulp-clean-css');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');  // js代码压缩

var watch = require('gulp-watch');
var connect = require('gulp-connect');
var clean = require('gulp-clean');

gulp.task('less',function(){
	return gulp.src(['./www/static/less/*.less'])
		.pipe(less())
		.pipe(autoprefixer({
			browsers: ['last 20 versions'],
			cascade: true
		}))
		.pipe(cleanCss())
		.pipe(gulp.dest('./www/static/less/'))
});

gulp.task('myless',function(){
	return gulp.src(['./www/static/less/global.less','./www/static/less/header.less','./www/static/less/footer.less','./www/static/less/quicknav.less'])
		.pipe(less())
		.pipe(autoprefixer({
			browsers: ['last 20 versions'],
			cascade: true
		}))
		.pipe(cleanCss())
		.pipe(concat('global.min.css'))
		.pipe(gulp.dest('./www/dist/'))
});

gulp.task('myjs',function(){
	return gulp.src(['./www/bower_components/seajs/dist/sea.js','./www/bower_components/jquery/dist/jquery.js','./www/bower_components/underscore/underscore.js'])
		.pipe(uglify())
		.pipe(concat('global.min.js'))
		.pipe(gulp.dest('./www/dist/'))
});

gulp.task('mywatch',function(){
	gulp.watch(['./www/static/less/*.less'],['less']);
});

gulp.task('localhost',function(){
	return connect.server({
		root: './www/',
		port: 6789
	});
});

gulp.task('default',['mywatch','localhost']);

